Next主题mac Panel代码块特效

Next自带的几款代码块,感觉不是很好看,查了一下发现了一款Mac Panel代码块特效,听名字就知道和Mac有关。安装完后代码块很像Mac terminal的风格,这个代码块特效很酷,比自带的几款确实要好看太多。。。

在Next主题的Script目录下创建events.js和codeblock.js文件

events.js添加以下内容:

1
2
3
4
5
var exec = require('child_process').exec;
hexo.on('new', function(data){
exec('open -a MacDown ' + data.path);
});

codeblock.js文件添加以下内容:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
var attributes = [
'autocomplete="off"',
'autocorrect="off"',
'autocapitalize="off"',
'spellcheck="false"',
'contenteditable="true"'
]
var attributesStr = attributes.join(' ')
hexo.extend.filter.register('after_post_render', function (data) {
while (/<figure class="highlight ([a-zA-Z]+)">.*?<\/figure>/.test(data.content)) {
data.content = data.content.replace(/<figure class="highlight ([a-zA-Z]+)">.*?<\/figure>/, function () {
var language = RegExp.$1 || 'plain'
var lastMatch = RegExp.lastMatch
lastMatch = lastMatch.replace(/<figure class="highlight /, '<figure class="iseeu highlight /')
return '<div class="highlight-wrap"' + attributesStr + 'data-rel="' + language.toUpperCase() + '">' + lastMatch + '</div>'
})
}
return data
})

在next\source\css_common\components\highlight\highlight.styl添加以下内容:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
.highlight-wrap[data-rel] {
position: relative;
overflow: hidden;
border-radius: 5px;
box-shadow: 0 10px 30px 0px rgba(0,0,0,0.4);
margin: 35px 0;
::-webkit-scrollbar {
height: 10px;
}
::-webkit-scrollbar-track {
-webkit-box-shadow: inset 0 0 6px rgba(0,0,0,0.3);
border-radius: 10px;
}
::-webkit-scrollbar-thumb {
border-radius: 10px;
-webkit-box-shadow: inset 0 0 6px rgba(0,0,0,0.5);
}
&::before {
color: white;
content: attr(data-rel);
height: 38px;
line-height: 38px;
background: #21252b;
color: #fff;
font-size: 16px;
position: absolute;
top: 0;
left: 0;
width: 100%;
font-family: 'Source Sans Pro', sans-serif;
font-weight: bold;
padding: 0px 80px;
text-indent: 15px;
float: left;
}
&::after {
content: " ";
position: absolute;
-webkit-border-radius: 50%;
border-radius: 50%;
background: #fc625d;
width: 12px;
height: 12px;
top: 0;
left: 20px;
margin-top: 13px;
-webkit-box-shadow: 20px 0px #fdbc40, 40px 0px #35cd4b;
box-shadow: 20px 0px #fdbc40, 40px 0px #35cd4b;
z-index: 3;
}
}

修改主题的_config.yml文件,代码高亮为:night eighties

1
2
$ cat _config.yml |grep high
highlight_theme: night eighties